//
//  TypeButton.swift
//  YOKO
//
//  Created by Zoe_G on 16/5/11.
//  Copyright © 2016年 15Tec. All rights reserved.
//

import UIKit

class TypeButton: UIButton {

    func initRoundBorder() {
        
        self.layer.cornerRadius = 5
        self.layer.borderWidth = 1
        self.layer.borderColor = UIColor.lightGrayColor().CGColor
        self.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        self.titleLabel?.adjustsFontSizeToFitWidth = true
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initRoundBorder()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        initRoundBorder()
    }
    
    func setFontSizeByHeight(height: CGFloat, withOffset offset: CGFloat) {
        
        self.titleLabel!.font = self.titleLabel!.font.fontWithSize(height - offset * 2)
        
    }
    
    func setToSelectedState() {
        
        self.layer.backgroundColor = UIColor.whiteColor().CGColor
        self.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        
    }
    func setToDiselectedState() {
        
        self.layer.backgroundColor = UIColor.clearColor().CGColor
        self.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
        
    }

}
